/**
 * Definition for an interval.
 * struct Interval {
 *     int start;
 *     int end;
 *     Interval() : start(0), end(0) {}
 *     Interval(int s, int e) : start(s), end(e) {}
 * };
 */
class Solution {
public:
    vector<Interval> merge(vector<Interval>& intervals) {
        vector<Interval> res{};
        for(auto n : intervals)
        {
            Interval temp = n;
            for(int i = 0; i < res.size(); i++)
            {
                if(temp.start > res[i].end || temp.end < res[i].start) continue;
                temp.start = min(temp.start, res[i].start);
                temp.end = max(temp.end, res[i].end);
                res.erase(res.begin() + i);
                i--;
            }
            res.push_back(temp);
        }
        return res;
    }
};
